package handlerUp

import (
	"fmt"
	"io"
	"os/exec"
	"sjy/auto_bd/config"
)

func Execute(confFile string, writer io.Writer) {
	cfg := config.ParseConfig(confFile)
	// 给权限
	cmd := exec.Command("chmod", "+x", cfg.ScriptURL)
	err := cmd.Run()
	if err != nil {
		panic(fmt.Errorf("executable permission error: %v", err))
	}

	// 构建shell
	cmd = exec.Command("/bin/bash", cfg.ScriptURL)

	// 设置标准输出和标准错误输出
	cmd.Stdout = writer
	cmd.Stderr = writer

	// 执行shell
	// output, err := cmd.CombinedOutput()
	err = cmd.Run()
	if err != nil {
		panic(fmt.Errorf("executing script faild: %v", err))
	}

}
